package com.cw.jeeyt.service.converter.system;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.service.bo.system.SystemTemplateModuleInfoBo;
import com.cw.jeeyt.dao.model.system.SystemTemplateModuleInfoDo;
import com.cw.lang.common.utils.CollectionUtil;

/**
 * 生成代码模板模块信息转换类
 *
 * @author chenw
 * @date 2019-03-10 13:04:25
 */
public class SystemTemplateModuleInfoConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static SystemTemplateModuleInfoBo do2Bo(SystemTemplateModuleInfoDo model) {
        if (model == null) {
            return null;
        }
        SystemTemplateModuleInfoBo bo = new SystemTemplateModuleInfoBo();
        bo.setId(model.getId());
        bo.setTemplateId(model.getTemplateId());
        bo.setTemplateModuleCode(model.getTemplateModuleCode());
        bo.setTemplateModuleName(model.getTemplateModuleName());
        bo.setTemplateModuleContent(model.getTemplateModuleContent());
        bo.setTemplateModuleComment(model.getTemplateModuleComment());
        bo.setTemplateModuleType(model.getTemplateModuleType());
        bo.setOutputFolder(model.getOutputFolder());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static SystemTemplateModuleInfoDo bo2Do(SystemTemplateModuleInfoBo bo) {
        if (bo == null) {
            return null;
        }
        SystemTemplateModuleInfoDo model = new SystemTemplateModuleInfoDo();
        model.setId(bo.getId());
        model.setTemplateId(bo.getTemplateId());
        model.setTemplateModuleCode(bo.getTemplateModuleCode());
        model.setTemplateModuleName(bo.getTemplateModuleName());
        model.setTemplateModuleContent(bo.getTemplateModuleContent());
        model.setTemplateModuleComment(bo.getTemplateModuleComment());
        model.setTemplateModuleType(bo.getTemplateModuleType());
        model.setOutputFolder(bo.getOutputFolder());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<SystemTemplateModuleInfoBo> doList2BoList(List<SystemTemplateModuleInfoDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), SystemTemplateModuleInfoConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<SystemTemplateModuleInfoDo> boList2DoList(List<SystemTemplateModuleInfoBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), SystemTemplateModuleInfoConverter::bo2Do));
    }
}